package com.kindergarten.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kindergarten.pojo.RolePage;
import com.kindergarten.mapper.RolePageMapper;
import com.kindergarten.service.IRolePageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bruce
 * @since 2022-11-03
 */
@Service
public class RolePageServiceImpl extends ServiceImpl<RolePageMapper, RolePage> implements IRolePageService {

    @Resource
    RolePageMapper rolePageMapper;

    @Override
    @Transactional
    public void updateRolePage(Integer roleId, Integer[] pageIds) {
        rolePageMapper.delete(new QueryWrapper<RolePage>().eq("role_id",roleId));
        if(pageIds.length != 0){
            for (Integer pageId : pageIds) {
                RolePage rolePage = new RolePage();
                rolePage.setRoleId(roleId);
                rolePage.setPageId(pageId);
                rolePageMapper.insert(rolePage);
            }
        }
    }
}
